﻿CREATE TRIGGER [ArticleCategories_insert_trigger] ON [ArticleCategories] FOR INSERT AS
UPDATE [side] SET [sync_row_is_tombstone] = 0, [local_update_peer_key] = 0, [restore_timestamp] = NULL, [update_scope_local_id] = NULL, [last_change_datetime] = GETDATE() FROM [ArticleCategories_tracking] [side] JOIN INSERTED AS [i] ON [side].[ArticleCategoryID] = [i].[ArticleCategoryID]
INSERT INTO [ArticleCategories_tracking] ([i].[ArticleCategoryID], [create_scope_local_id], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime], [restore_timestamp]) SELECT [i].[ArticleCategoryID], NULL, 0, @@DBTS+1, NULL, 0, 0, GETDATE() , NULL FROM INSERTED AS [i] LEFT JOIN [ArticleCategories_tracking] [side] ON [side].[ArticleCategoryID] = [i].[ArticleCategoryID] WHERE [side].[ArticleCategoryID] IS NULL